<?php
include_once "../token.php";
$urlgo="https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=".get_access_token();
$pdata = '
    {
          "industry_id1":"8",
          "industry_id2":"9"
       }
';
//echo postData($urlgo, $pdata); 
//设置行业end

$u2="https://api.weixin.qq.com/cgi-bin/template/get_industry?access_token=".get_access_token();
//echo file_get_contents($u2); 
//获取行业信息


//获取模板id
$u3="https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=".get_access_token();
$p2data = '
    {
        "template_id_short":"OPENTM207261556"
    }
';

//echo postData($u3, $p2data); 



//get tag id
$url_gettag="https://api.weixin.qq.com/cgi-bin/tags/get?access_token=".get_access_token();
//echo file_get_contents($url_gettag); 

//get users by tag
$url_user="https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=".get_access_token();
$pdata_tag= '
    {
  "tagid" : '.$_GET["uid"].',
  "next_openid":""//第一个拉取的OPENID，不填默认从头开始拉取
    }
';
//$http_result=postData($url_user, $pdata_tag); 




$url_ewm="https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=".get_access_token();
$pdata_ewm= '
{"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": "123"}}}
';
$ewm_result=json_decode(postData($url_ewm, $pdata_ewm));

if(array_key_exists("errcode",$ewm_result)){
			echo "force_get_access_token";
			$newtoken=force_get_access_token();
		}else{
		echo "no errcode";
		}
function setUser($url_user,$pdata_tag){
$result = json_decode(file_get_contents("user_list".$_GET["uid"].".json"),true);
  if( $result['expires_in']  < time() ){
		echo "updata user list ";
		$getContent=postData($url_user, $pdata_tag); 
		echo $getContent;
        $res = json_decode($getContent,true);
        $access_token = $res["data"]["openid"];   //重新获取的access_token
        if($access_token){
            $reflesh['expires_in'] = time()+7000;
            $reflesh['user_list'] = $access_token;
            $fp = fopen("user_list".$_GET["uid"].".json", "w");
            fwrite($fp, json_encode($reflesh));
            fclose($fp);
        }

    }else{
		echo "expires_in error ";
      $access_token = $result['user_list'];
    }
	return $access_token;
}
//$json_result=json_decode($http_result);

date_default_timezone_set("PRC");
$user_list_array=setUser($url_user,$pdata_tag);
Print_r($user_list_array);
echo "this result check user_list /n";
if($_GET["fx"]=="buy"){
	$action="看涨";
}else{
	$action="看跌";
}
$weekarray=array("日","一","二","三","四","五","六");
$xqj="星期".$weekarray[date("w")];



$time_saved=file_get_contents($_GET["symbol"].$_GET["timeFrame"]."timenow.json");
echo $time_saved."-".$_GET["timenow"]."<br>";
if($time_saved!=$_GET["timenow"]){
$fp = fopen($_GET["symbol"].$_GET["timeFrame"]."timenow.json", "w");
fwrite($fp, $_GET["timenow"]);
fclose($fp);

$ArrayList_url = array(); 
$ArrayList_data = array(); 
foreach($user_list_array as $value)    
{       

	//发送模板信息
$u4="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".get_access_token();
$p3data='
	 {
           "touser":"'.$value.'",
           "template_id":"r9wbyHJ4cmeLinM0sI083CPTkBhrvo7BwVTxvzl2iww",
           "url":"http://m.zuikuapp.com/a/513317_1452649.html?from=singlemessage&isappinstalled=0",            
           "data":{
                   "first": {
                       "value":"操作方向:长期'.$action.'(方浩程序②喊单)",
                       "color":"#FF0033"
                   },
                   "keyword1":{
                       "value":"'.$_GET["symbol"].'",
                       "color":"#FF0033"
                   },
                   "keyword2": {
                       "value":"'.$_GET["price"].'",
                       "color":"#FF0033"
                   },
                   "keyword3": {
                       "value":"'. date("Y-m-d").' '.$xqj.' '.date("H:i:s").'(北京时间)",
                       "color":"#FF0033"
                   },
                   "remark":{
                       "value":"温馨提示：方浩投资建议您轻仓交易：本金除以20000得到交易的手数，以镑日为基准设置70点止损，100点止盈（或反向信号平仓，或依据方浩软件的支撑位和阻力位平仓）。如需其他货币对的喊单服务，请联系我们销售热线：400-830-1361",
                       "color":"#000"
                   }
           }
       }
';  
//echo $p3data."<br>"; 
$ArrayList_url[]= $u4;
$ArrayList_data[]=$p3data;
//echo postData($u4, $p3data); 
}
$resl=curl_multi_post($ArrayList_url,$ArrayList_data);
//print_r($resl);
}





